<template>
  <div class="collect">
    <ItemHeader :menuArr="categoryArr" @navFn="selectThis">
      <span slot="leftBtn">
        <!-- <a href="javascript:void(0)" @click="showSetPaymentBox()" class="fr">提问设置</a> -->
      </span>
    </ItemHeader>
    <div>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import ItemHeader from '@/components/dashboardAuth/item-header'
export default {
  data () {
    return {
      // selectedIndex: 0,
      // categoryArr: ['问答', '计划', '观点'],
      categoryArr: [{ name: '问答', route: '/dashboardAuth/collect/qa' }, { name: '计划', route: '/dashboardAuth/collect/plan' }, { name: '观点', route: '/dashboardAuth/collect/viewpoint' }],
      categoryArrPath: ['/mycollect/qa', '/mycollect/plan', '/mycollect/viewpoint'], // 普通用户
      categoryArrPathForAuth: ['/dashboardAuth/collect/qa', '/dashboardAuth/collect/plan', '/dashboardAuth/collect/viewpoint'] // 投顾
    }
  },
  components: {
    ItemHeader
  },
  mounted () {
    // let index = this.findIndex(this.categoryArrPath)
    // if (index >= 0) {
    //   this.selectedIndex = index
    // } else {
    //   this.selectedIndex = this.findIndex(this.categoryArrPathForAuth)
    // }
  },
  methods: {
    findIndex (arr) {
      let path = this.$route.path
      let index = -1
      for (let i = 0; i < arr.length; i++) {
        if (path.indexOf(arr[i]) >= 0) {
          index = i
          break
        }
      }
      return index
    },
    selectThis (index) {
      let arr = this.categoryArrPath
      if (this.$route.path.indexOf('dashboardAuth') > 0) {
        arr = this.categoryArrPathForAuth
      }
      this.$router.push(arr[index])
    }
  }
}
</script>

<style lang="scss">
@import "../../../style/res/collect";
</style>
